-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Improves UART reading performance #7525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In esp32-hal-uart.c->uartRead(), int len = uart_read_bytes(uart->num, &c, 1, 20 / portTICK_RATE_MS);
can return negative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR drops call to available(). Likely OK, but need to test both HardwareSerial::read(void)
and HardwareSerial::read(uint8_t *buffer, size_t size)
when no data available to see if there are any side effects with calling IDF function uart_read_bytes() with 0 timeout.
PR looks promising. I see no other issues.
I tested it using the example sketch of this PR. |
Sketch Example has been updated to test return of read(buffer) when there is no data to be read. |
@SuGlider I am getting this output from the sketch on ESP32-S2 (did not test other chips yet).
Is that right? If yes maybe update the expected OUTPUT :) |
Also did a quick test of the performance of the reading as the sketch is written (only Serial.prints removed). Before changes reading 36 bytes took 316-325 us. Seems a really nice speed improvement. Great PR @SuGlider |
New commit e072302 overrides |
Thanks. Example and Output are now updated. |
@SuGlider See my review comments above, especially on readBytes(). |
This one #7525 (review)? |
The code already treats negative return:
|
@SuGlider Apologies, Github is being weird about my review notes and is showing review as pending (but not posted?). I'll cancel the review, look over the current code and just comment here. |
On cores/esp32/HardwareSerial.h On cores/esp32/esp32-hal-uart.c On cores/esp32/esp32-hal-uart.c
Also consider marking uartRead() as |
It is a bit confusing to review code this way. Do you mind using the traditional way as below: When reviewing it within GitHub, you can use 2 buttons: The Red Arrow will insert the review immediately. |
Thanks @mrengineer7777 for the review.
Yes, correct. Fixed now.
Yes, noted. Both functions are now fixed.
Actually the functions exposed in esp32-hal-uart.c shall not be used by the application. |
@SuGlider Apologies for not replying sooner. Hectic day at work yesterday. Your explanation on Github review buttons is very helpful. Just read through all the code changes again. With your latest commits PR looks good to me. |
@mrengineer7777 - Thank you for the code review! |
Description of Change
Improves UART reading more than 1 bytes, using
HardwareSerial::read(uint8_t *buff, size_t len)
Tests scenarios
Tested with ESP32, ESP32S2, ESP32S3, ESP32C3 using this sketch and a Python script runing on a computer.
See #7505
General Testing Sketch:
Expected OUPUT when sending 0123456789abcdefghijklmnopqrstuvwxyz
Related links
Fixes #7505
Fixes #7474
May Fix #6644
May Fix #6727